﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Web.BaseCode;

namespace BlogDH
{
    public class CommValue
    {

        /// <summary>
        /// 列表显示的文章数量
        /// </summary>
        public static int PageSize
        {
            get { return Common.ConfigHelper.GetConfigInt("PageSize"); }
        }


        /// <summary>
        /// 首页第一页文章
        /// </summary>
        public static System.Data.DataSet HomeBlogList
        {
            get
            {
                System.Data.DataSet ds = null;
                Object obj = CacheProvider.GetCache("HomeBlogList");
                if (obj == null)
                {
                    BLL.BlogInfo bll = new BLL.BlogInfo();
                    ds = bll.GetPageList(PageSize, 1, HomeBlogListCount, null);
                    CacheProvider.SetCache("HomeBlogList", ds, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration);
                }
                else
                {
                    ds = (System.Data.DataSet)obj;
                }
                return ds;
            }
        }

        /// <summary>
        /// 首页文章总数量
        /// </summary>
        public static int HomeBlogListCount
        {
            get
            {
                int count = 0;
                Object obj = CacheProvider.GetCache("HomeBlogListCount");
                if (obj == null)
                {
                    BLL.BlogInfo bll = new BLL.BlogInfo();
                    count = bll.GetRecordCount();
                    CacheProvider.SetCache("HomeBlogListCount", count, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration);
                }
                else
                {
                    count = (int)obj;
                }
                return count;
            }

        }

        /// <summary>
        /// 地区列表
        /// </summary>
        public static List<Model.Area> AreaList
        {
            get
            {
                List<Model.Area> areas = null;
                Object obj = CacheProvider.GetCache("AreaList");

                if (obj == null)
                {
                    areas = new BLL.Area().GetModelList("pid=0");
                    CacheProvider.SetCache("AreaList", areas, DateTime.Now.AddDays(1), System.Web.Caching.Cache.NoSlidingExpiration);
                }
                else
                {
                    areas = (List<Model.Area>)obj;
                }

                return areas;
            }

        }
    }
}